package edu.sju.ssm.serviceImpl;

import java.io.BufferedWriter;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

import edu.sju.ssm.service.PrintingService;

public class FilePrintingService implements PrintingService {

	private String filePath;
	private String message;
	
	
	public FilePrintingService() {
	}


	public FilePrintingService(String filePath, String message) {
		this.filePath = filePath;
		this.message = message;
	}


	public String getFilePath() {
		return filePath;
	}


	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}


	public String getMessage() {
		return message;
	}


	public void setMessage(String message) {
		this.message = message;
	}


	@Override
	public void print() {
		 try (BufferedWriter bw = Files.newBufferedWriter(
				 Path.of(filePath), StandardCharsets.UTF_8, StandardOpenOption.CREATE)) {
	            bw.write(message);
	            bw.newLine();
	            bw.flush();
	            bw.close();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	}

}
